package com.maimao.order.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.maimao.model.order.Order;
import com.maimao.model.order.es.EsOrder;
import com.maimao.model.order.vo.OrderEx;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Set;

/**
 * @author MaoLin Wang
 * @date 2021/1/18 5:46 下午
 */
@Mapper
public interface OrderMapper extends BaseMapper<Order> {
    int cancel(@Param("orderId") Long orderId, @Param("status") Integer status, @Param("closeTime") LocalDateTime closeTime);

    Order selectStatus(@Param("orderId") Long orderId);

    int updateStatus(@Param("id") Long orderId, @Param("status") Integer status);
    int updateStatusAndPayTime(@Param("id")Long orderId,@Param("status") Integer status,@Param("payTime") LocalDateTime payTime);


    List<OrderEx> selectCompleteData(@Param("userId") Long userId, @Param("comment") Integer commentType,
                                     @Param("fromTime") LocalDateTime fromTime,
                                     @Param("toTime") LocalDateTime toTime, @Param("status") Integer status,
                                     @Param("shippedStatus")Integer shippedStatus,
                                     @Param("receive")Integer receive,
                                     @Param("orderId") Long orderId, @Param("title") String title,
                                     @Param("goodsId") Long goodsId, @Param("shopId") Long shopId,
                                     @Param("deleted")Integer deleted,
                                     @Param("page") Integer page, @Param("size") Integer size);

    /**
     * #selectCompleteData 的未分页情况下的所有结果集的orderShopId集合，作为#selectCompleteData的分页结果总数
     */
    Set<Long> selectCompleteDataCount(@Param("userId") Long userId, @Param("comment") Integer commentType,
                                      @Param("fromTime") LocalDateTime fromTime,
                                      @Param("toTime") LocalDateTime toTime, @Param("status") Integer status,
                                      @Param("shippedStatus")Integer shippedStatus,
                                      @Param("receive")Integer receive,
                                      @Param("orderId") Long orderId, @Param("title") String title,
                                      @Param("deleted")Integer deleted,
                                      @Param("goodsId") Long goodsId, @Param("shopId") Long shopId
    );

    int deleteLogic(@Param("id") Long id);

    List<EsOrder> selectEsOrderBySharding(@Param("index") int shardIndex, @Param("total") int shardTotal);


    /**
     * 查询订单完整数据（order+orderShop+orderGoods）
     */
//    List<OrderEx> selectCompleteData(@Param("userId") Long userId);
//    List<Order> selectCompleteData2(@Param("userId") Long userId);
 /* List<OrderEx> selectCompleteData(@Param("userId") Long userId, @Param("orderId") Long orderId,
                                     @Param("status") Integer status,@Param("fromTime")LocalDateTime fromTime,@Param("toTime")LocalDateTime toTime);*/
}
